SWEP.Author   		= "MadDog"
SWEP.Contact        = ""
SWEP.Purpose        = ""
SWEP.Instructions   = "Put out ze fire!"
SWEP.Spawnable      = true
SWEP.AdminSpawnable  = true

SWEP.ViewModel      = "models/weapons/v_fire_extinguisher.mdl"
SWEP.WorldModel   = "models/weapons/w_fire_extinguisher.mdl"

SWEP.Primary.Delay			= 0.9 	--In seconds
SWEP.Primary.Recoil			= 0		--Gun Kick
SWEP.Primary.Damage			= 15	--Damage per Bullet
SWEP.Primary.NumShots		= 1		--Number of shots per one fire
SWEP.Primary.Cone			= 0 	--Bullet Spread
SWEP.Primary.ClipSize		= 10	--Use "-1 if there are no clips"
SWEP.Primary.DefaultClip	= 10	--Number of shots in next clip
SWEP.Primary.Automatic   	= true	--Pistol fire (false) or SMG fire (true)
SWEP.Primary.Ammo         	= "pistol"	--Ammo Type

SWEP.Secondary.Delay		= 0.9
SWEP.Secondary.Recoil		= 0
SWEP.Secondary.Damage		= 0
SWEP.Secondary.NumShots		= 1
SWEP.Secondary.Cone			= 0
SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic   	= true
SWEP.Secondary.Ammo         = "none"


if ( SERVER ) then
	AddCSLuaFile( "shared.lua" )

	SWEP.HoldType			= "shotgun"
end

if ( CLIENT ) then
	SWEP.PrintName			= "Fire Extinguisher"
	SWEP.Slot				= 1
	SWEP.SlotPos			= 8
	SWEP.ViewModelFOV		= 70
end

function SWEP:Initialize()
	util.PrecacheSound("ambient/wind/wind_hit2.wav")
end

function SWEP:PrimaryAttack()
	if CLIENT then return end

	
	
	
	local tr = util.TraceLine({
		start = self.Owner:GetShootPos(),
		endpos = (self.Owner:GetShootPos() + (self.Owner:GetAimVector() * 150)),
		filter = self.Owner
	})
	

	if !tr.Hit then return end

	local _ents = ents.FindInSphere( tr.HitPos, 20 )

	for _, ent in pairs( _ents ) do
		
		if (ent:IsOnFire()) then
			ent:Extinguish()
		end
--[[
			if ent:IsNPC() or ent:IsPlayer() then
				local b = ents.Create( "point_hurt" )
				b:SetKeyValue("targetname", "fier" ) --Yes, I spelled it like that on purpose.
				b:SetKeyValue("DamageRadius", "20" )
				b:SetKeyValue("Damage", "5" )
				b:SetKeyValue("DamageDelay", "1" )
				b:SetKeyValue("DamageType", "16" )
				b:SetPos( ent:GetPos())
				b:Spawn()
				b:Fire("turnon", "", 0)
				b:Fire("kill", "", 5)
			end
]]

	end

	--local Pos1 = tr.HitPos + tr.HitNormal
	--local Pos2 = tr.HitPos - tr.HitNormal
	--util.Decal( "hl1glassbreak", Pos1, Pos2 )

	self:Smoke(self.Owner, "500", "50", "2", "20", "500")
	self.Weapon:EmitSound("ambient/wind/wind_hit2.wav")
	self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
	self.Weapon:SetNextPrimaryFire(CurTime() + .2)
end

function SWEP:Smoke(ent, speed, rate, size1, size2, length)
	if !SERVER then return end

	self.smoke = ents.Create("env_steam")
	self.smoke:SetOwner( self.Owner )

	--if ent:IsPlayer() then
	--	self.smoke:SetPos(ent:GetShootPos())
	--	self.smoke:SetKeyValue("Angles", tostring(ent:EyeAngles()))
	--else
		self.smoke:SetPos( self.Owner:GetShootPos() )
		self.smoke:SetKeyValue("Angles", tostring(ent:EyeAngles()))
	--end

	self.smoke:SetKeyValue("InitialState", "1")
	self.smoke:SetKeyValue("Speed", speed)
	self.smoke:SetKeyValue("Rate", rate)
	self.smoke:SetKeyValue("StartSize", size1)
	self.smoke:SetKeyValue("EndSize", size2)
	self.smoke:SetKeyValue("JetLength", length)
	self.smoke:SetKeyValue("SpreadSpeed", "2")
	self.smoke:SetKeyValue("SpawnFlags", "1")
	self.smoke:Spawn()
	self.smoke:Activate()
	self.smoke:Fire("TurnOn", "", 0)
	self.smoke:Fire("TurnOff","", .25)
	self.smoke:Fire("kill", "", 1)
end
